<template>
	<view class="c-container no-border order-container">
		<!-- 订单基本信息 -->

		<!-- 选择订单类型等 -->
		<common-basic :isPreview="basicPreview" :order="order" :orderParams="orderParams" :weddingParams="weddingParams"
			:banquetParams="banquetParams" :babyParams="babyParams" :meetingParams="meetingParams"
			@resetValue="resetValue" @resetSettlement="resetSettlement" @getConfirmSequence="getConfirmSequence" />

		<!-- 酒店信息 -->
		<hotel :order="order" :orderParams="orderParams" />

		<!-- 非宝宝宴、会务的联系方式，婚期等 -->
		<common-contact v-if="!['7', '8', '11', '12'].includes(orderParams.news_type)" :orderParams="orderParams"
			:order="order" :startDate="startDate" :endDate="endDate" />

		<!-- 宝宝宴类型订单的联系方式、婚期等 -->
		<baby-contact v-if="orderParams.news_type == 7 && [3, 4, 2].includes(orderParams.order_nature)"
			:orderParams="orderParams" :order="order" :startDate="startDate" :endDate="endDate" />

		<!-- 定金 -->
		<view class="c-row-box" v-if="orderParams.order_nature == 3">
			<view class="c-row-head">
				<view class="c-row-title">定金金额</view>
			</view>
			<view class="c-row-item">
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">定金金额</view>
						<view class="col-text"><input type="text" v-model="orderParams.prepay_money"
								placeholder="请输入" /></view>
					</view>
				</view>
			</view>
		</view>

		<!-- 意向金 -->
		<view class="c-row-box" v-if="orderParams.order_nature == 4">
			<view class="c-row-head">
				<view class="c-row-title">意向金额</view>
			</view>
			<view class="c-row-item">
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">意向金额</view>
						<view class="col-text"><input type="text" v-model="orderParams.prepay_money"
								placeholder="请输入" /></view>
					</view>
				</view>
			</view>
		</view>

		<!-- 销售信息,宝宝宴、会务没有引流销售 -->
		<sale v-if="!['7', '8', '11', '12'].includes(orderParams.news_type)" :orderParams="orderParams" />

		<!-- 婚宴信息:订单状态下(order_nature=1)，信息类型为婚宴(news_type=0)或一站式(news_type=2)的时候显示 -->
		<banquet v-if="['0', '2'].includes(orderParams.news_type) && ![3, 2, 4].includes(orderParams.order_nature)"
			:banquetParams="banquetParams" :order="order" @getOrderTotals="getOrderTotals"
			@getOtherPrice="getOtherPrice" />

		<!-- 婚庆信息:订单状态下(order_nature=1)，信息类型为婚庆(news_type=1)或一站式(new_type=2)的时候显示 -->
		<wedding v-if="['1', '2'].includes(orderParams.news_type) && ![3, 2, 4].includes(orderParams.order_nature)"
			:order="order" :weddingParams="weddingParams" @getOrderTotals="getOrderTotals"
			@getOtherPrice="getOtherPrice" />

		<!-- 宝宝宴信息:订单状态下(order_nature=2),信息类型为宝宝宴（news_type=7）的时候显示 -->
		<baby v-if="orderParams.news_type == '7' && ![3, 2, 4].includes(orderParams.order_nature)"
			:babyParams="babyParams" :orderParams="orderParams" :order="order" :startDate="startDate" :endDate="endDate"
			@getOrderTotals="getOrderTotals" />

		<!--会务信息：非定金、意向金（order_nature not in (3,4)）,信息类型为会务（news_type=8）的时候显示 -->
		<meeting :meetingParams="meetingParams" :orderParams="orderParams"
			v-if="orderParams.news_type == '8' && !include(orderParams.order_nature, [3, 4])" :parent="_self"></meeting>

		<!-- 活动信息 11,12 activities -->
		<activities :activitiesParams="activitiesParams" :orderParams="orderParams"
			v-if="orderParams.news_type == '11' || orderParams.news_type == '12'" :parent="_self"></activities>

		<!-- 其他项目列表 -->
		<other-item-list v-if="orderParams.order_nature != 5 && addons.length > 0" :addons="addons"
			:parent="_self"></other-item-list>

		<!-- 婚车信息：信息类型为婚车，或者存在赠送婚车的情况 -->
		<car v-if="orderParams.news_type == '4' || hasCarPresent" :parent="_self" :carParams="carParams"
			:orderParams="orderParams" @getOrderTotals="getOrderTotals" />

		<!-- 结算信息：返佣单（order_nature=2）的时候显示 -->
		<commission v-if="orderParams.order_nature == 2" :parent="_self" :settleParams="settleParams"
			:startDate="startDate" :endDate="endDate" :orderParams="orderParams" />

		<!-- 收款信息 -->
		<income ref="income"
			v-if="!include(orderParams.order_nature, [0, 2]) && orderParams.cooperation_mode != 1 && !include(orderParams.news_type, [11,12])"
			:incomeParams="incomeParams" :orderParams="orderParams" :startDate="startDate" :endDate="endDate"
			:incomeNature="orderParams.order_nature" :incomeType="orderParams.news_type + ''"
			@getTailMoney="getTailMoney" @resetIncome="resetIncome" />

		<!-- 定金收款 -->
		<earnest-money v-if="
				incomeParams.income_item_price &&
					![0, 2].includes(orderParams.order_nature) &&
					incomeParams.income_type == 1 &&
					orderParams.order_nature != 3 &&
					orderParams.order_nature != 4 &&
					orderParams.order_nature != 5
			" :orderParams="orderParams" :incomeParams="incomeParams" :startDate="startDate" :endDate="endDate" />

		<!-- 中款收款 -->
		<middle-money v-if="
				incomeParams.income_item_price &&
					![0, 2].includes(orderParams.order_nature) &&
					incomeParams.income_type == 1 &&
					orderParams.order_nature != 3 &&
					orderParams.order_nature != 4 &&
					orderParams.order_nature != 5 &&
					(orderParams.order_nature==1 && orderParams.news_type!=7)
			" :orderParams="orderParams" :startDate="startDate" :endDate="endDate" @getTailMoney="getTailMoney"
			@getMiddleChange="getMiddleChange" />

		<!-- 尾款收款 -->
		<tail-money v-if="
				orderParams.middle_money != '' &&
					![0, 2].includes(orderParams.order_nature) &&
					incomeParams.income_type == 1 &&
					orderParams.order_nature != 3 &&
					orderParams.order_nature != 4 &&
					orderParams.order_nature != 5
			" :orderParams="orderParams" :startDate="startDate" :endDate="endDate" @getMiddleMoney="getMiddleMoney"
			@getTailChange="getTailChange" />

		<!-- 合同信息 -->
		<contract-note v-if="!include(orderParams.news_type, [11,12])" :orderParams="orderParams" />

		<!-- 离开缓存订单 -->
		<uni-popup ref="popupsStorege" type="dialog" style="z-index: 999;">
			<uni-popup-dialog type="input" message="成功消息" title="提示" content="是否要保存本次修改的信息？" :duration="2000"
				confirmText="确定" cancelText="取消" :before-close="true" @close="closesStorege"
				@confirm="confirmsStorege"></uni-popup-dialog>
		</uni-popup>

		<!-- 审核流程 -->
		<view class="confirm-list" v-if="confirmStep.length > 0">
			<divider title="审核流程"></divider>
			<steps-look ref="step" :stepList="confirmStep"></steps-look>
		</view>

		<!-- 获取缓存信息 -->
		<uni-popup ref="popupsGetStorege" type="dialog" style="z-index: 999;">
			<uni-popup-dialog type="input" message="成功消息" title="提示" content="是否要继续编辑上次信息？" :duration="2000"
				confirmText="确定" cancelText="取消" :before-close="true" @close="closesGetStorege"
				@confirm="confirmsGetStorege"></uni-popup-dialog>
		</uni-popup>

		<!-- 添加、查看赠送项目 -->
		<append-other-item ref="appendOtherItem" :parent="_self"></append-other-item>

		<!-- 页面底部栏 -->
		<view class="footer-box">
			<view class="footer-text">
				<text>合同总额：{{ orderParams.totals }}</text>
			</view>
			<view class="footer-action-btn">
				<button size="mini" v-if="orderParams.order_nature==1 || orderParams.order_nature==2"
					@click="showAppendOtherItemDialog(false, {})">添加项目</button>
				<button size="mini" @click="submit">生成预览</button>
			</view>
		</view>
	</view>
</template>

<script>
	import request from '@/utils/request.js';
	import dictionary from '@/utils/dictionary.js';
	import formater from '@/utils/formater.js';
	import {
		checkObjLen,
		include
	} from '@/utils/common.js';

	// 订单性质、订单类型、成单公司、合同号等信息
	import commonBasic from './common/basic.vue';
	// 酒店、厅信息
	import hotel from './common/hotel.vue';
	// 非宝宝宴订单信息的联系方式、举办时间、签单时间
	import commonContact from './common/contact.vue';
	// 宝宝宴订单信息的联系方式、举办时间、签单时间
	import babyContact from './babay/contact.vue';
	// 引流销售信息
	import sale from './common/sale.vue';
	// 婚宴详情信息
	import banquet from './banquet/detail.vue';
	// 婚庆信息
	import wedding from './wedding/detail.vue';
	// 宝宝宴信息
	import baby from './babay/detail.vue';
	// 会务信息
	import meeting from './meeting/detail.vue';
	// 活动信息
	import activities from './activities/detail.vue';

	// 所选的婚车信息
	import car from './car/list.vue';
	// 返佣单信息
	import commission from './common/commission.vue';
	// 定金金额信息
	import earnestMoney from './common/contract.earnest.vue';
	// 中款金额信息
	import middleMoney from './common/contract.middle.vue';
	import tailMoney from './common/contract.tail.vue';
	// 收款信息
	import income from './common/income.vue';
	// 小票信息
	import contractNote from './common/contract.note.vue';
	// 其他赠送项目
	import otherItemList from './otherItem/list.vue';
	// 添加其他项目
	import appendOtherItem from './otherItem/append.vue';
	import stepsLook from '@/component/steps-look/steps-look.vue'; // 新版审核流程
	import divider from '@/component/divider/divider';

	// 加载配置文件
	import config from './config.js';
	import ruleForms from './ruleForms.js'
	import {
		nextTick
	} from '../../../component/vant/dist/common/utils';

	export default {
		provide() {
			return {
				createOrder: this,
			}
		},
		components: {
			commonBasic,
			hotel,
			commonContact,
			babyContact,
			sale,
			banquet,
			wedding,
			baby,
			meeting,
			activities,
			car,
			commission,
			earnestMoney,
			middleMoney,
			tailMoney,
			income,
			contractNote,
			otherItemList,
			appendOtherItem,
			stepsLook,
			divider
		},
		data() {
			return {
				id: '', // 客资ID
				member_id: '', // 客资ID，缓存数据用，不参与传参
				member_allocate_id: '',

				hallList: [],
				carTypeList: config.carTypeList,

				// 添加婚车每一项
				addCarItem: Object.assign({}, config.carItem),

				confirm_id: 0,
				carTypeDialog: false, //添加婚车

				// 其他费用
				otherPriceItem: Object.assign({}, config.otherPriceItem),
				otherContent: '', //选择其他类型时填写其他内容
				tagTitleList: '',

				// 其他费用列表
				addons: [],
				hasCarPresent: false,
				isEdit: false,
				// 增项项目
				addType: config.addTypeList,
				// 合作模式
				mode: config.modeList,
				order: ruleForms.order,
				// 订单主体参数
				orderParams: ruleForms.orderParams,
				// 婚宴信息
				banquetParams: ruleForms.banquetParams,
				// 婚庆信息
				weddingParams: ruleForms.weddingParams,
				// 宝宝宴信息
				babyParams: ruleForms.babyParams,
				// 会务信息
				meetingParams: ruleForms.meetingParams,
				// 活动信息
				activitiesParams: ruleForms.activitiesParams,
				carParams: [],
				// 结算信息
				settleParams: ruleForms.settleParams,
				// 其他项目信息
				otherPirce: 0,
				incomeParams: ruleForms.incomeParams,
				confirmStep: [], // 审核流程
				basicPreview: false,
			};
		},
		computed: {
			companyList: function() {
				return dictionary.getPicker('companyList');
			},
			orderType: function() {
				return dictionary.getPicker('newsTypeList');
			},
			paymentList: function() {
				return dictionary.getPicker('paymentList');
			},
			ritualList: function() {
				return dictionary.getPicker('ritualList');
			}
		},
		onLoad(options) {
			this.orderParams.middle_money = '';
			this.orderParams.middle_money_date = ''
			if (options.toOrder) {
				// 定金转订单
				let order = this.order;
				let orderOrigin = JSON.parse(decodeURIComponent(options.toOrder));
				console.log(orderOrigin)

				order.company_id = orderOrigin.company_id;
				order.news_type = orderOrigin.news_type;
				// 同步订单信息
				let orderParams = this.orderParams;
				orderParams.pid = orderOrigin.id;
				orderParams.company_id = orderOrigin.company_id;
				orderParams.order_nature = 1;
				orderParams.news_type = orderOrigin.news_type + '';
				orderParams.hotel_id = orderOrigin.hotel_id;
				orderParams.hotel_text = orderOrigin.hotel_text;
				orderParams.bridegroom = orderOrigin.bridegroom;
				orderParams.bridegroom_mobile = orderOrigin.bridegroom_mobile;
				orderParams.bride = orderOrigin.bride;
				orderParams.bride_mobile = orderOrigin.bride_mobile;
				orderParams.event_date = formater.formatDate(orderOrigin.event_date);
				orderParams.id_card = orderOrigin.id_card;
				orderParams.home_address = orderOrigin.home_address;
				orderParams.member_id = orderOrigin.member_id;
				orderParams.parent_totals = parseFloat(orderOrigin.prepay_money);
				orderParams.audit_type = 'order';

				this.orderParams = orderParams;
				// 同步订单客资信息
				this.member_id = orderOrigin.member_id;
				this.member_allocate_id = orderOrigin.member_allocate_id ? orderOrigin.member_allocate_id : 0;
				// 获取审核流程
				this.getConfirmSequence();
			} else if (options.toCommission) {
				// 返佣单
				let order = this.order;
				let orderOrigin = JSON.parse(decodeURIComponent(options.toCommission));

				order.company_id = orderOrigin.company_id;
				order.news_type = orderOrigin.news_type + '';
				// 同步订单信息
				let orderParams = this.orderParams;
				orderParams.pid = orderOrigin.id;
				orderParams.company_id = orderOrigin.company_id;
				orderParams.order_nature = 2;
				orderParams.news_type = '0';
				orderParams.hotel_id = orderOrigin.hotel_id;
				orderParams.hotel_text = orderOrigin.hotel_text;
				orderParams.bridegroom = orderOrigin.bridegroom;
				orderParams.bridegroom_mobile = orderOrigin.bridegroom_mobile;
				orderParams.bride = orderOrigin.bride;
				orderParams.bride_mobile = orderOrigin.bride_mobile;
				orderParams.event_date = formater.formatDate(orderOrigin.event_date);
				orderParams.id_card = orderOrigin.id_card;
				orderParams.home_address = orderOrigin.home_address;
				orderParams.member_id = orderOrigin.member_id;
				orderParams.cooperation_mode = '1';
				orderParams.audit_type = 'order';
				orderParams.parent_totals = parseFloat(orderOrigin.prepay_money);
				this.orderParams = orderParams;
				// 同步订单客资信息
				this.member_id = orderOrigin.member_id;
				this.member_allocate_id = orderOrigin.member_allocate_id ? orderOrigin.member_allocate_id : 0;
				// 获取审核流程
				this.getConfirmSequence();
			} else if (options.confirm_id) {
				// 审核驳回,重新提交
				this.confirm_id = options.confirm_id;
				this.getRejectOrder();
			} else {
				// 获取缓存订单
				this.id = options.id;
				this.member_id = options.member_id;
				this.member_allocate_id = options.member_allocate_id;
				if (uni.getStorageSync('setOrder')) {
					this.$nextTick(function() {
						this.$refs.popupsGetStorege.open();
					});
				} else {
					this.getHistoryOrder();
				}
			}

			if (this.$refs.income) {
				this.$nextTick(() => {
					this.$refs.income.getIncomeNature("order", "")
				})
			}


		},
		beforeMount() {
			this.checkObjLen = checkObjLen;
			this.dictionary = dictionary;
			this.include = include;
		},
		// 监听页面离开
		onBackPress() {
			this.$refs.popupsStorege.open();
			return true;
		},
		computed: {
			startDate() {
				return ruleForms.getFormatDate('start');
			},
			endDate() {
				return ruleForms.getFormatDate('end');
			}
		},
		methods: {
			// 定金、意向金转订单
			transformToOrder() {

			},
			// 转意向金
			transformToCommission() {

			},
			// 检查是否有历史订单
			getHistoryOrder() {
				let that = this;
				request.request({
					url: '/api/audit.order/getMemberLastOrder',
					showLoading: true,
					token: true,
					data: {
						member_id: that.member_id
					},
					success(res) {
						if (res.code == 200) {
							let data = res.data.existedOrder;
							if (data) {
								uni.showModal({
									content: '是否同步历史订单信息',
									success(res) {
										if (res.confirm) {
											that.orderParams.bride = data.bride;
											that.orderParams.bride_mobile = data.bride_mobile;
											that.orderParams.bridegroom = data.bridegroom;
											that.orderParams.bridegroom_mobile = data.bridegroom_mobile;
											that.orderParams.sign_date = data.sign_date;
											that.orderParams.event_date = data.event_date;
											that.orderParams.id_card = data.id_card;
											that.orderParams.home_address = data.home_address;
										}
									}
								});
							}
						}
					}
				});
			},

			// 如果是驳回订单，获取订单信息
			getRejectOrder() {
				let that = this;
				let params = {};
				params['order_confirm_id'] = that.confirm_id;

				request.request({
					url: '/api/audit.order/origin',
					showLoading: true,
					token: true,
					data: params,
					success(res) {
						if (res.code == 200) {
							let data = res.data;
							// 必须包含 parent_totals;
							that.orderParams = Object.assign(that.orderParams, data.order);
							that.orderParams.news_type = that.orderParams.news_type ? that.orderParams.news_type +
								'' : '';
							that.orderParams.cooperation_mode = that.orderParams.cooperation_mode ? that
								.orderParams.cooperation_mode + '' : 0;
							// 获取已选就点的厅列表
							that.hallList = data.hallList;
							if (data.order.complete && data.order.complete == 99) {
								// 意向金
								that.orderParams.order_nature = 4;
								that.orderParams.complete = 99;
							} else if (data.order.complete && data.order.complete == 98) {
								that.orderParams.order_nature = 3;
								that.orderParams.complete = 98;
							} else {
								that.orderParams.complete = 0; // 普通订单
								if (data.order.cooperation_mode == 1) {
									// 返佣单
									that.orderParams.order_nature = 2;
								}
							}
							// 同步酒店名称，酒店比较多，不能放在配置文件中，这个方案还没处理的太好
							that.order.hotel = data.order.hotel_text;
							that.order.hotel = data.order.hotel_text;
							// 同步婚宴信息
							if (checkObjLen(data.banquet)) that.banquetParams = data.banquet;
							// 同步婚庆信息
							if (checkObjLen(data.wedding)) that.weddingParams = data.wedding;
							// 同步宝宝宴信息
							if (checkObjLen(data.baby)) that.babyParams = data.baby;
							// 同步会务信息
							if (checkObjLen(data.meeting)) that.meetingParams = data.meeting;
							// 同步推广信息
							if (checkObjLen(data.activities) && ['11', '12'].includes(that.orderParams
								.news_type)) {
								that.activitiesParams = data.activities;
								that.basicPreview = true
							}
							// 同步返佣单信息
							that.settleParams = data.settlement;
							if (checkObjLen(data.car)) {
								that.carParams = data.car;
								that.hasCarPresent = true;
							}
							that.incomeParams = data.income;
							that.addons = data.order.addons;
							// 同步客资信息
							that.member_id = data.order.member_id;
							that.member_allocate_id = data.order.member_allocate_id ? data.order
								.member_allocate_id : 0;
							// 获取审核流程
							console.log(that.orderParams.order_nature)

							that.getConfirmSequence();
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg
							});
						}
					}
				});
			},

			// 获取审核信息
			getConfirmSequence() {
				let that = this;
				request.request({
					url: '/api/order.audit/getAuditProcess',
					showLoading: true,
					token: true,
					data: Object.assign({
						order: that.orderParams
					}, {
						audit_type: that.orderParams.audit_type
					}),
					success(res) {
						if (res.code == 200) {
							that.confirmStep = res.data.process;
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg
							});
						}
					}
				});
				// that.incomeParams.income_type = 1;
			},

			//确认是否获取缓存信息
			confirmsGetStorege() {
				this.getTorge();
				this.$refs.popupsGetStorege.close();
			},

			//获取缓存信息
			getTorge() {
				let setOrderData = uni.getStorageSync('setOrder');
				if (setOrderData) {
					Object.assign(this.$data, setOrderData);
				}
				this.$forceUpdate();
			},

			//取消获取缓存信息
			closesGetStorege() {
				this.$refs.popupsGetStorege.close();
				this.getHistoryOrder();
			},

			// 保存修改信息
			confirmsStorege() {
				let that = this;
				this.setorge();
				uni.switchTab({
					url: '../../customerList/customerList'
				});
				that.$refs.popupsStorege.close();
			},

			// 缓存信息
			setorge() {
				let setOrder = this.$data;
				console.log(setOrder)
				delete setOrder.id;
				uni.setStorageSync('setOrder', setOrder);
			},

			// 不保存修改信息
			closesStorege() {
				this.$refs.popupsStorege.close();
				uni.switchTab({
					url: '../../customerList/customerList'
				});
				uni.removeStorageSync('setOrder');
			},

			// 添加其他售卖信息
			showAppendOtherItemDialog(isEdit, item) {
				this.$refs["appendOtherItem"].showDialog(isEdit, item)
			},

			// 获取合同总额
			getOrderTotals() {
				let that = this;
				//驳回订单重新提交  算出之前添加的其他增项价格总和
				let otherPirce = 0;
				that.addons.forEach((item, index) => {
					otherPirce += parseFloat(item.total);
				});

				// 算出之前添加的婚车价格总和
				let sum = 0;
				that.carParams.forEach((item, index) => {
					sum += parseFloat(item.car_total);
				});

				let currentCar_totals =
					parseFloat(this.addCarItem.car_amount == '' ? 0 : this.addCarItem.car_amount) *
					parseFloat(this.addCarItem.car_price == '' ? 0 : this.addCarItem.car_price).toFixed(2);
				let banquet_totals = that.banquetParams.banquet_totals ? that.banquetParams.banquet_totals : 0;
				let wedding_totals = that.weddingParams.wedding_totals ? that.weddingParams.wedding_totals : 0;
				// let car_total = that.carParams.car_total ? that.carParams.car_total : 0;
				// 当前输入婚车价格和之前添加的婚车价格总和
				let car_total = (sum ? sum : 0) + (currentCar_totals ? currentCar_totals : 0);
				let baby_total = that.babyParams.baby_totals ? that.babyParams.baby_totals : 0;
				let settle_totals = that.settleParams.settle_totals ? that.settleParams.settle_totals : 0;
				let meeting_total = that.meetingParams.meeting_totals ? that.meetingParams.meeting_totals : 0;
				// console.log(meeting_total);

				that.orderParams.totals = (
					parseFloat(banquet_totals) +
					parseFloat(wedding_totals) +
					parseFloat(otherPirce) +
					parseFloat(car_total) +
					parseFloat(baby_total) +
					parseFloat(settle_totals) +
					parseFloat(meeting_total)
				).toFixed(2);
				that.getTailMoney();
			},

			// 获取其他费用
			getOtherPrice(data) {
				let otherPirce = 0;
				let len = data.length;
				for (let i = 0; i < len; i++) {
					otherPirce = otherPirce + parseFloat(data[i]['total']);
				}
				this.otherPirce = otherPirce;
				this.orderParams.otherList = data;
				this.getOrderTotals();
			},

			// 获取中款金额
			getMiddleMoney() {
				let that = this;
				let parent_totals = that.orderParams.parent_totals;
				let orderTotal = that.orderParams.totals;
				let earnest_money = that.incomeParams.income_item_price;
				let tail_moeny = that.orderParams.tail_money;
				that.orderParams.middle_money = (parseFloat(orderTotal) - parseFloat(earnest_money) - parseFloat(
					tail_moeny) - parseFloat(parent_totals)).toFixed(2);
			},

			//订单中 的中尾款收款时间，限制不能低于订单时间不能高于举办时间
			getMiddleChange() {
				let that = this;
				let getIncomeTime = new Date(that.incomeParams.income_date); //获取定金时间
				let getMiddleTime = new Date(that.orderParams.middle_money_date); //获取中款时间
				let getEventDate = new Date(that.orderParams.event_date); //获取举办
				let getSignDate = new Date(that.orderParams.sign_date); //获取签单时间

				let getIncome = getIncomeTime.getTime();
				let getMiddle = getMiddleTime.getTime();
				let getEvent = getEventDate.getTime();
				let getSign = getSignDate.getTime();

				if (that.incomeParams.income_type != 7 && that.orderParams.order_nature == 1&& that.orderParams.news_type != 7 && getMiddleTime > 0) {
					if (getMiddle < getSign) {
						uni.showToast({
							icon: 'none',
							title: '中款时间低于订单时间~'
						});
						return false;
					} else if (getMiddle > getEvent) {
						uni.showToast({
							icon: 'none',
							title: '中款时间高于举办时间!~'
						});
						return false;
					}
				}
			},

			getTailChange() {
				let that = this;
				let getEventDate = new Date(that.orderParams.event_date); //获取举办
				let getSignDate = new Date(that.orderParams.sign_date); //获取签单时间
				let getTailTime = new Date(that.orderParams.tail_money_date); //获取尾款时间

				let getTail = getTailTime.getTime();
				let getEvent = getEventDate.getTime();
				let getSign = getSignDate.getTime();
				let weikuan = getEventDate.setMonth(getEventDate.getMonth() + 3);

				if (that.incomeParams.income_type != 7 && that.orderParams.order_nature == 1 && getTailTime > 0) {
					if (that.orderParams.news_type == '8') {
						//会务尾款时间高于举办时间3个月
						if (getTail < getSign) {
							uni.showToast({
								icon: 'none',
								title: '尾款时间低于订单时间~'
							});
							return false;
						} else if (getTail > weikuan) {
							uni.showToast({
								icon: 'none',
								title: '尾款时间高于举办时间3个月~'
							});
							return false;
						}
					} else {
						if (getTail < getSign) {
							uni.showToast({
								icon: 'none',
								title: '尾款时间低于订单时间~'
							});
							return false;
						} else if (getTail > getEvent) {
							uni.showToast({
								icon: 'none',
								title: '尾款时间高于举办时间~'
							});
							return false;
						}
					}
				}
			},

			// 获取尾款金额
			getTailMoney() {
				let that = this;
				let parent_totals = that.orderParams.parent_totals;
				let orderTotal = that.orderParams.totals;
				let earnest_money = parseFloat(that.incomeParams.income_item_price);
				this.orderParams.earnest_money = earnest_money + parent_totals;
				let middle_money = that.orderParams.middle_money == '' ? 0 : that.orderParams.middle_money;
				that.orderParams.tail_money = (parseFloat(orderTotal) - parseFloat(earnest_money) - parseFloat(
					middle_money) - parseFloat(parent_totals)).toFixed(2);
			},

			// 选项更改时，重置
			resetValue() {
				this.banquetParams = {
					company_id: 0,
					table_amount: '',
					table_price: '',
					banquet_discount: '',
					banquet_totals: 0
				};

				this.weddingParams = {
					company_id: 0,
					wedding_package_id: '',
					product_no: '',
					wedding_discount: '',
					wedding_package_price: '',
					wedding_totals: 0
				};

				this.babyParams = {
					company_id: 0,
					customer_name: '',
					customer_mobile: '',
					party_remark: '',
					arrangement: '', // 布置
					table_amount: '',
					food_totals: 0,
					table_price: '',
					baby_discount: '',
					baby_totals: 0
				};

				this.incomeParams = {
					receivable_no: '',
					income_payment: '',
					income_payment_text: '请选择',
					income_type: 1,
					income_type_text: '请选择',
					income_item_price: '',
					income_date: '请选择'
				};

				this.otherPirce = 0;
				this.orderParams.otherList = [];
				this.orderParams.totals = 0;
			},

			// 重置结算信息
			resetSettlement() {
				this.settleParams = {
					table_amount: 0,
					table_price: 0,
					settle_totals: 0,
					settle_percent: '',
					settle_time: '请选择',
					settle_real_total: 0,
					settle_remark: ''
				};
			},

			// 收款方式发生改变时，清除收款信息
			resetIncome() {
				this.orderParams.earnest_money = 0;
				this.orderParams.earnest_money_date = '';
				this.orderParams.middle_money = '';
				this.orderParams.middle_money_date = '';
				this.orderParams.tail_money = 0;
				this.orderParams.tail_money_date = '';
			},

			// 生成预览
			submit() {
				let that = this;
				let id = that.member_id;
				if (['11', '12'].includes(that.orderParams.news_type) && that.orderParams.order_nature == 5) {
					if (that.activitiesParams.startDate == '' || that.activitiesParams.end_date == '' || that
						.activitiesParams.position == '') {
						uni.showToast({
							icon: 'none',
							title: '请填写推广信息~'
						});
						return false
					}
				}

				that.setorge();
				uni.navigateTo({
					url: './previewOrder?member_id=' + id
				});
			},
		}
	};
</script>

<style lang="less">
	uni-page-body {
		padding-top: 0;
	}

	@import url("../components/common.less");
	@import url("./components/common.less");

	.order-container {
		padding-bottom: 102upx;

		.footer-box {
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			padding: 0 16px;
			display: flex;
			align-items: center;
			height: 100upx;
			font-size: 28upx;
			background-color: #ffffff;
			border-top: 1px solid #dedede;
			z-index: 9;

			.footer-title {
				flex: 0 15%;
			}

			.footer-action-btn {
				flex: 1;
				text-align: end;

				button {
					background-color: #007aff;
					color: #ffffff;
				}

				button+button {
					margin-left: 5px;
				}
			}
		}
	}
</style>